package com.ruix.app.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * Created by hadexs on 2017/5/11.
 */

public class LessonInfo implements Serializable{
    private String id; //课ID
    private int num; //参与人数
    private String name; //课名
    private ArrayList<String> album; //图片列表
    private String audio; //音频
    private long discussTime; //共修时间
    private String chatId;
    private int lastReport;//上次记录

    public LessonInfo parse(JSONObject object){
        if (object != null){
            setId(object.optString("id",""));
            setName(object.optString("name",""));
            setAudio(object.optString("audio",""));
            setDiscussTime(object.optLong("discuss_at",0) * 1000);
            setNum(object.optInt("num",0));
            setChatId(object.optString("chatid",""));

//            report
            JSONObject lastPoint =  object.optJSONObject("last_point");
            if (lastPoint != null) {
              setLastReport(lastPoint.optInt("report", 0) *1000); //毫秒
            }

            //
            JSONArray albumArray = object.optJSONArray("album");
            if (albumArray != null && albumArray.length() > 0) {
                album = new ArrayList();
                for (int i = 0; i < albumArray.length(); i++) {
                    album.add(albumArray.optString(i, ""));
                }
            }

        }
        return this;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ArrayList<String> getAlbum() {
        return album;
    }

    public void setAlbum(ArrayList<String> album) {
        this.album = album;
    }

    public String getAudio() {
        return audio;
    }

    public void setAudio(String audio) {
        this.audio = audio;
    }

    public long getDiscussTime() {
        return discussTime;
    }

    public void setDiscussTime(long discussTime) {
        this.discussTime = discussTime;
    }


    public String getDisplayStudyTime() {
        if (discussTime > 0) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
            Date d1 = new Date(discussTime);
            return format.format(d1);
        }
        return "";
    }

    public String getChatId() {
        return chatId;
    }

    public void setChatId(String chatId) {
        this.chatId = chatId;
    }


    public int getLastReport() {
        return lastReport;
    }

    public void setLastReport(int lastReport) {
        this.lastReport = lastReport;
    }

    @Override
    public String toString() {
        return "LessonInfo{" +
                "id='" + id + '\'' +
                ", num=" + num +
                ", name='" + name + '\'' +
                ", album=" + album +
                ", audio='" + audio + '\'' +
                ", discussTime=" + discussTime +
                '}';
    }
}
